package com.leetcode.merci.lc617;

import com.leetcode.merci.TreeNode;

/**
 * Created by bowen on 2017/7/23.
 */
public class Solution {
    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        return toMake(t1,t2);
    }
    public TreeNode toMake(TreeNode t1,TreeNode t2){
        TreeNode result=null;
        if(t1==null && t2==null){
            return null;
        }
        if(t1!=null && t2!=null){
            result = new TreeNode(t1.val+t2.val);
            result.left = toMake(t1.left, t2.left);
            result.right = toMake(t1.right, t2.right);
        }
        else if(t1==null){
            result =new TreeNode(t2.val);
            result.left = toMake(null, t2.left);
            result.right = toMake(null, t2.right);
        }
        else if(t2==null){
            result=new TreeNode(t1.val);
            result.left = toMake(t1.left, null);
            result.right = toMake(t1.right, null);
        }
        return result;
    }
}
